package org.lzuploader.model.result;

/** This class contains a character's upload results.
 * 
 * @author Emmanuel Cron
 *
 */ 
public class ResultCharacter implements Comparable<ResultCharacter>
{
    /** An "ok" status code. */
    public static final int OK = 0;
    
    /** An "invalid guild" status code. */
    public static final int INVALID_GUILD = 1;
    
    /** A "not owned by account" status code. */
    public static final int NOT_OWNED = 2;
    
    /** Status code of the data. */
    private int statusCode;
    
    /** Name of this character. */
    private String name;
    
    /** Wether the character has correctly been updated or not. */
    private boolean characterUpdate;
    
    /** Wether the character's professions have been correctly deleted or not. */
    private boolean professionDelete;
    
    /** Number of crafts updated, or <code>-1</code> if error. */
    private int craftsUpdated = -1;
    
    /** Number of reagents updated, or <code>-1</code> if error. */
    private int reagentsUpdated = -1;
    
    /** Number of dungeons updated, or <code>-1</code> if error. */
    private int dungeonsUpdated = -1;
    
    /** Number of crafts specializations updated, or <code>-1</code> if error. */
    private int craftsSpecializationsUpdated = -1;
    
    /**
     * Returns the status code of this character's data.
     * If this status code equals {@link ResultCharacter#OK}, then this character should be processed,
     * otherwise it should not be processed.
     * @return An status code, either {@link ResultCharacter#OK}, {@link ResultCharacter#INVALID_GUILD} or {@link ResultCharacter#NOT_OWNED}.
     */
    public int getStatusCode()
    {
        return statusCode;
    }
    
    /**
     * Sets the status code of this character's data.
     * @param newStatusCode A status code, either {@link ResultCharacter#OK}, {@link ResultCharacter#INVALID_GUILD} or {@link ResultCharacter#NOT_OWNED}.
     */
    public void setStatusCode(final int newStatusCode)
    {
        statusCode = newStatusCode;
    }
    
    /** Returns the name of this character.
     * 
     * @return The character's name.
     */
    public String getName()
    {
        return name;
    }
    
    /**
     * Sets the name of this character.
     * @param newName The new name.
     */
    public void setName(final String newName)
    {
        name = newName;
    }
    
    /** Returns wether this character has been updated.
     * 
     * @return <code>true</code> if character has been updated, <code>false</code> otherwise.
     */
    public boolean isCharacterUpdated()
    {
        return characterUpdate;
    }
    
    /**
     * Sets wether this character has been updated.
     * @param newCharacterUpdate <code>true</code> if character has been updated, <code>false</code> otherwise.
     */
    public void setCharacterUpdated(final boolean newCharacterUpdate)
    {
        characterUpdate = newCharacterUpdate;
    }
    
    /**
     * Returns wether the character's professions have been deleted.
     * @return <code>true</code> if professions have been deleted, <code>false</code> otherwise.
     */
    public boolean isProfessionsDeleted()
    {
        return professionDelete;
    }
    
    /**
     * Returns wether the character's professions have been deleted.
     * @return <code>true</code> if professions have been deleted, <code>false</code> otherwise.
     */
    public boolean getProfessionsDeleted()
    {
        return professionDelete;
    }
    
    /**
     * Sets wether the character's professions have been deleted.
     * @param newProfessionDelete <code>true</code> if professions have been deleted, <code>false</code> otherwise.
     */
    public void setProfessionsDeleted(final boolean newProfessionDelete)
    {
        professionDelete = newProfessionDelete;
    }
    
    /** Returns wether the character's crafts have been updated.
     * 
     * @return <code>true</code> if crafts have been updated, <code>false</code> otherwise.
     */
    public boolean isCraftsUpdated()
    {
        return craftsUpdated < 0;
    }
    
    /**
     * Returns the number of crafts updated.
     * @return Number of crafts updated, or <code>-1</code> if an error occured.
     */
    public int getCraftsUpdated()
    {
        return craftsUpdated;
    }
    
    /**
     * Sets the number of crafts updated.
     * @param newCraftsUpdated Number of crafts updated.
     */
    public void setCraftsUpdated(final int newCraftsUpdated)
    {
        craftsUpdated = newCraftsUpdated;
    }
    
    /** Returns wether the character's reagents have been updated.
     * 
     * @return <code>true</code> if reagents have been updated, <code>false</code> otherwise.
     */
    public boolean isReagentsUpdated()
    {
        return reagentsUpdated < 0;
    }
    
    /** Returns the number of reagents updated.
     * 
     * @return Number of reagents updated, or <code>-1</code> if an error occured.
     */
    public int getReagentsUpdated()
    {
        return reagentsUpdated;
    }
    
    /**
     * Sets the number of reagents updated.
     * @param newReagentsUpdated Number of reagents updated.
     */
    public void setReagentsUpdated(final int newReagentsUpdated)
    {
        reagentsUpdated = newReagentsUpdated;
    }
    
    /** Returns wether the character's dungeons have been updated.
     * 
     * @return <code>true</code> if dungeons have been updated, <code>false</code> otherwise.
     */
    public boolean isDungeonsUpdated()
    {
        return dungeonsUpdated < 0;
    }
    
    /** Returns the number of dungeons updated.
     * 
     * @return Number of dungeons updated, or <code>-1</code> if an error occured.
     */
    public int getDungeonsUpdated()
    {
        return dungeonsUpdated;
    }
    
    /**
     * Sets the number of dungeons updated.
     * @param newDungeonsUpdated Number of dungeons updated.
     */
    public void setDungeonsUpdated(final int newDungeonsUpdated)
    {
        dungeonsUpdated = newDungeonsUpdated;
    }
    
    /** Returns wether the character's spells have been updated.
     * 
     * @return <code>true</code> if spells have been updated, <code>false</code> otherwise.
     */
    public boolean isSpellsUpdated()
    {
        return craftsSpecializationsUpdated < 0;
    }
    
    /** Returns the number of crafts specializations updated.
     * 
     * @return Number of crafts specializations updated, or <code>-1</code> if an error occured.
     */
    public int getCraftsSpecializationsUpdated()
    {
        return craftsSpecializationsUpdated;
    }
    
    /**
     * Sets the number of crafts specializations updated.
     * @param newCraftsSpecializationsUpdated Number of specializations.
     */
    public void setCraftsSpecializationsUpdated(final int newCraftsSpecializationsUpdated)
    {
        craftsSpecializationsUpdated = newCraftsSpecializationsUpdated;
    }
    
    /**
     * Returns a string representing this class in a human readable way.
     * @return A string representing this class.
     */
    @Override
    public String toString()
    {
        final StringBuffer sb = new StringBuffer();
        
        sb.append("[ ");
        sb.append("Name: " + name + ", ");
        sb.append("Status: ");
        
        switch (statusCode)
        {
            case INVALID_GUILD:
                sb.append("INVALID_GUILD");
                break;
            case NOT_OWNED:
                sb.append("NOT_OWNED");
                break;
            case OK:
                sb.append("OK");
                break;
            default:
                sb.append("UNKNOWN");
        }
        
        if (statusCode == OK)
        {
            sb.append(", ");
            sb.append("Update: " + characterUpdate  + ", ");
            sb.append("Professions deleted: " + professionDelete + ", ");
            sb.append("Crafts updated: " + craftsUpdated + ", ");
            sb.append("Reagents updated: " + reagentsUpdated + ", ");
            sb.append("Dungeons updated: " + dungeonsUpdated + ", ");
            sb.append("Crafts specializations updated: " + craftsSpecializationsUpdated);
        }
        
        sb.append(" ]");
        
        return sb.toString();
    }

    /**
     * Compares two objects with their name.
     * @param o Object to compare with this one.
     * @return a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
     */
    @Override
    public int compareTo(final ResultCharacter o)
    {
        return this.getName().compareToIgnoreCase(o.getName());
    }
}
